/**************************************************************************
 * @doc CPAC
 * @module CPAC CPACPRNT.H |
 * Source code for the CPAC handling functions.
 * Product         :   SoftPay 2000 (Global Payment Methodology).
 * <nl>Developer   :   SoftPay Development Team (I_SP2000).
 * <nl>Notes       :
 * @head3 CPAC Printer related Functions |
 * @index | CPAC
 * @end
 *
 * Copyright (c) 1996-2000 by VeriFone Inc. All rights reserved.
 *
 * No part of this software may be used, stored, compiled, reproduced,
 * modified, transcribed, translated, transmitted, or transferred, in any form
 * or by any means whether electronic, mechanical, magnetic, optical,
 * or otherwise, without the express prior written permission of VeriFone, Inc.
 *
 * Revision History
 * ------------------------------------------------------------------------
 $Log: /SoftPay/SPK2SIM/Source/CPACSrc/cpacprnt.h $

********************************************************************************/

#ifndef _CPAC_PRNT_H_
#define _CPAC_PRNT_H_

#include <iso8583.h>
#include <amexhost.h>
#include <transact.h>
#include "..\cpacsrc\cpac.h"
#include <protocol.h>
#include <packet.h>
#include <sizes.h>
/***** Receipt Printing *****/
#define HEADER2_START     11 /* LENIN CPAC TEMP */
//Kelvin_F2 --- start : Chinese tx code printing
#ifndef HKGM
#define HEADER2_END       23 /* LENIN CPAC TEMP */
#endif /*HKGM*/
#ifdef HKGM
#define HEADER2_END       22 /* For HKGM, chinese tran type use line 23 */
#define TRAN_CODE_LINE_START 23
#define TRAN_CODE_LINE_END 23
#endif /*HKGM*/
//Kelvin_F2 --- end: Chinese tx code printing

/*#define BOTTOM_END                    85  // added after the integration with the 1.05 version B of the core.
//#define AMOUNT_START              38
//#define AMOUNT_END                    52
//#define CPAC_DETAIL_TOP_START         230
//#define CPAC_DETAIL_TOP_END           250
//#define CPAC_DETAIL_MIDDLE_START  110
//#define CPAC_DETAIL_MIDDLE_END        120
#define CPAC_BOTTOM_END             70 */
#define CPAC_MIDDLE_START           24
#define CPAC_MIDDLE_END             37
#define AMOUNT_START                38
#define AMOUNT_END                  59  // Original 52
#define CPAC_SIGN_LINE_START        60  // Original AMOUNT_END + 1 (53)
#define CPAC_SIGN_LINE_END          70  // Original CPAC_BOTTOM_END (70)
#define CPAC_BOTTOM_START           71  // Newly added
#define CPAC_BOTTOM_END             84  // Original CPAC_BOTTOM_END + 10 (80)
#define CPAC_RECEIPT_FOOTER_START   85
#define CPAC_RECEIPT_FOOTER_END     110
#define BOTTOM_END                  85  // added after the integration with the 1.05 version B of the core.
//#define CPAC_SUMMARY_MIDDLE_START 168
//#define CPAC_SUMMARY_MIDDLE_END       180
//#define CPAC_SUMMARY_TOP_START        160
#define CPAC_SUMMARY_FORM_FEED_END  196 */
//#define CPAC_SUMMARY_FORM_FEED        191
//#define CPAC_SUMMARY_FORM_FEED_END    196
#define PRT_BANK                    64
//Kelvin_F2 --- start: reset the line number
/**** Common Report Session ****/
#define CPAC_FORM_FEED_START            198
#define CPAC_FORM_FEED_END              198
#define CPAC_END_OF_REPORT_START        197  /* Because no line 197 in the phil template, */
#define CPAC_END_OF_REPORT_END          198  /* It will have the same effect as from feed */

/**** Summary Report and Settlement Report ****/
#define CPAC_SETTLEMENT_STATUS_START    37
#define CPAC_SETTLEMENT_STATUS_END      40    /* original 39 */
#define CPAC_SUMMARY_TOP_START          160
#define CPAC_SUMMARY_TOP_END            170   /* original 167 */
#define CPAC_SUMMARY_MIDDLE_START       171   /* original 168 */
#define CPAC_SUMMARY_MIDDLE_END         185   /* original 180 */
#define CPAC_SUMMARY_BOTTOM_START       186   /* original 181 */
#define CPAC_SUMMARY_BOTTOM_END         196   /* original 190 */
#define CPAC_GRANT_TOTAL_LABEL_START    199
#define CPAC_GRANT_TOTAL_LABEL_END      200

/**** Detail Report ****/
#define CPAC_DETAIL_TOP_START           230
#define CPAC_DETAIL_TOP_END             250
#define CPAC_DETAIL_MIDDLE_START        110
#define CPAC_DETAIL_MIDDLE_END          119  /* original is 120 */
#define CPAC_DETAIL_BOTTOM_START        120  /* original is DETAIL_BOTTOM_START  120 */
#define CPAC_DETAIL_BOTTOM_END          135  /* original is DETAIL_BOTTOM_END 135 */
#define CPAC_CREDIT_LABEL_START         50   /* original is hard code 50 */
#define CPAC_CREDIT_LABEL_END           51   /* original is hard code 51 */
#define CPAC_DETAIL_TOTAL_START         52   /* original is hard code 52 */
#define CPAC_DETAIL_TOTAL_END           52   /* original is hard code 52 */
#define CPAC_TOTAL_LABEL_START          53   /* original is hard code 53 */
#define CPAC_TOTAL_LABEL_END            54   /* original is hard code 54 */
#define CPAC_EMPTY_LINE_START           55
#define CPAC_EMPTY_LINE_END             55

/**** Status Report ****/
//#ifdef HKGM
#define CPAC_STATS_TOP_START            11
#define CPAC_STATS_TOP_END              17
#define CPAC_STATS_MIDDLE_START         18
#define CPAC_STATS_MIDDLE_END           29
#define CPAC_STATS_EOR_START            30
#define CPAC_STATS_EOR_END              30
// #endif /* HKGM */

/***** Clerk Detail Report ****/
#define CPAC_CLERK_DATE_START           20
#define CPAC_CLERK_DATE_END             21
#define CPAC_CLERK_DETAIL_TOP_START     110
#define CPAC_CLERK_DETAIL_TOP_END       122
#define CPAC_CLERK_DETAIL_MIDDLE_START  125
#define CPAC_CLERK_DETAIL_MIDDLE_END    129
#define CPAC_CLERK_DETAIL_BOTTOM_START  130
#define CPAC_CLERK_DETAIL_BOTTOM_END    145
#define CPAC_CLERK_DETAIL_EOR_START     63 /* Share with the EOR of Clerk Table Report */
#define CPAC_CLERK_DETAIL_EOR_END       65 /* Share with the EOR of Clerk Table Report */

/**** Clerk Table Report ***/
#define CPAC_CLERK_TABLE_TOP_START      50
#define CPAC_CLERK_TABLE_TOP_END        60
#define CPAC_CLERK_TABLE_MIDDLE_START   61
#define CPAC_CLERK_TABLE_MIDDLE_END     62
#define CPAC_CLERK_TABLE_BOTTOM_START   63
#define CPAC_CLERK_TABLE_BOTTOM_END     65

/**** Clerk Total Report ****/
#define CPAC_CLERK_TOTAL_TOP_START      20
#define CPAC_CLERK_TOTAL_TOP_END        30
#define CPAC_CLERK_TOTAL_BOTTOM_START   41
#define CPAC_CLERK_TOTAL_BOTTOM_END     49
#define CPAC_CLERK_TOTAL_EOR_START      63
#define CPAC_CLERK_TOTAL_EOR_END        65
//Kelvin_F2 --- end: reset the line number

typedef struct {
    char szPAN[PAN_SIZE + 1];
    char szTranType[TRAN_TYPE_MSG_SIZE + 1];
    char szCardLabel[CLABEL_SIZE + 1];
}CPAC_CUST_DETAIL_REPORTS_FIELDS;


/* Saritha_b1 .......Start.....Reprint Settlement Report */

// #ifdef TLFB  (Made this feature as the part of CPAC Base Application)

typedef struct TAGCPACSETTLEHEADER {
    char szDate[FORMATTED_DATE_SIZE + 1];
    char szTime[FORMATTED_TIME_SIZE + 1];
    char szMID[MERCH_ID_SIZE + 1];
    char szTID[TERM_ID_SIZE + 1];
    char szBatchNum[BATCH_NUM_SIZE + 1];
    char szHostName[HOST_NAME_SIZE + 1];
    char szBottemMsg[MESSAGE_SIZE + 1];
    unsigned long lnHeaderCond;
#ifdef AMEX_SOC
    char szSOC[RESP_MSG_SIZE + 1];
#endif /*  AMEX_SOC */
} CPAC_SETTLE_HEADER;


typedef struct TAGCPACSETTLEMIDDLE {
    char szCardName[CLABEL_SIZE + 1];
    char szCreditCnt[INT_STR_SIZE + 1];
    char szCreditTot[FORMATTED_AMOUNT_SIZE + 1];
    char szDebitCnt[INT_STR_SIZE + 1];
    char szDebitTot[FORMATTED_AMOUNT_SIZE + 1];
    char szShiftNum[INT_STR_SIZE + 1];
 #ifdef CITI_SING //jrd
	char szShiftEPPSale[INT_STR_SIZE + 1];
	char szEPPSaleCount[INT_STR_SIZE + 1];
  	char szEPPSaleSurchrgeTotal[FORMATTED_AMOUNT_SIZE + 1];
 #endif	//CITI_SING
    char szSurCharge[FORMATTED_AMOUNT_SIZE + 1];
 #ifdef CASHCARD_DEFINED		//meca 20041023 -- fixed from cashcard O3750 -- to correct the problem with totals report -- start
	char szCashOutTot[FORMATTED_AMOUNT_SIZE+ 1];
	char szSChrgCnt[INT_STR_SIZE];
 #endif	//CASHCARD_DEFINED		//meca 20041023 -- fixed from cashcard O3750 -- to correct the problem with totals report -- end
    char szAdjCnt[INT_STR_SIZE + 1];
    char szAdjTot[FORMATTED_AMOUNT_SIZE + 1];
    char szReversalCnt[INT_STR_SIZE + 1];
    char szReversalTot[FORMATTED_AMOUNT_SIZE + 1];
    char szNetCnt[INT_STR_SIZE + 1];
    char szNetTot[FORMATTED_AMOUNT_SIZE + 1];
    unsigned long lnMiddleCond;
} CPAC_SETTLE_MIDDLE;

#define CPAC_RESETTLEMENT_REPORT_FILE "crs"
#define CPAC_HEADER         1
#define CPAC_BODY           2
#define CPAC_FOOTER         3



typedef struct TAGCPACCSETTLEBOTTOM {
    unsigned long lnBottomCond;
}CPAC_SETTLE_BOTTOM;

// #endif  /* TLFB */ (Made this feature as the part of CPAC Base Application)

/* Saritha_b1 .......End.....Reprint Settlement Report */





////////////////////////////////////////////////////////////////////
//
// E X T E R N   D E C L A R A T I O N S
//

////////////////////////////////////////////////////////////////////
//
// F U N C T I O N   P R O T O T Y P E S
//
int inCPACPrintReportHeader(TRANSACTION_OBJECT* pobTran); //NOT USE NOW

void vdCPACMakeDetailMiddle(TRANSACTION_OBJECT* pobTran,DETAIL_TOTALS* psrDetTot);
/***** For Receipt Printing *****/
void vdMakeReceiptTop(TRANSACTION_OBJECT* pobTran);
void vdCPACMakeReceiptAfterResp(TRANSACTION_OBJECT* pobTran);
void vdSetPrintHeaderCondition2(TRANSACTION_OBJECT* pobTran);
void vdSetPrintReceiptConditions(TRANSACTION_OBJECT* pobTran);
void vdSetReceiptFooterConditions(TRANSACTION_OBJECT* pobTran);


extern int inCITIFlowPrintReceipt(TRANSACTION_OBJECT* pobTran);
int inCPACReprintRecpt(long lnInvNum,PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran,int inChoice);
int inCPACGetReceiptCopy(TRANSACTION_OBJECT* pobTran,int inChoice);
int inCPACReprintLastReceiptOperation(TRANSACTION_OBJECT* pobTran);

int inCPACPrintReceiptTop(TRANSACTION_OBJECT* pobTran);
int inPrintReceiptHeader2(PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran);
int inCPACPrintReceiptBottom(TRANSACTION_OBJECT* pobTran);
//int inCPACPrintReportHeader(PRINTER_OBJECT *obPrinter);
int inCPACPrintReceiptMiddle(PRINTER_OBJECT* obPrinter);
int inCPACPrintReceiptBottomLines(PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran);
int inPrintReceiptFooterLines(PRINTER_OBJECT* obPrinter);
/***** For Detail Report Printing *****/
int inCPACReportInit(TRANSACTION_OBJECT* pobTran);
int inCPACPrintDetailReport(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter);
int inCPACPrintClerkReportHeader(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter);
int inCPACPrintDetailMiddle(PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran,DETAIL_TOTALS* psrDetTot);
void vdCPACMakeDetailMiddle(TRANSACTION_OBJECT* pobTran,DETAIL_TOTALS* psrDetTot);
void vdCPACSetDetailHeaderCondition(int inReportTop,int inCurrencyFlag);
int inCPACPrintDetailGrandTotal(PRINTER_OBJECT* pobPrinter,TRANSACTION_OBJECT* pobTran,int* pinReportTop,int inNumberOfMerchants);
int inImamPrintDetailGrandTotal(PRINTER_OBJECT* pobPrinter,TRANSACTION_OBJECT* pobTran,int* pinReportTop,int inNumberOfMerchants);
/***** For Summary Report Printing *****/
int inCPACSummaryReportOperation(TRANSACTION_OBJECT* pobTran);

int inCPACPrintSummaryReport(PRINTER_OBJECT* pobPrinter,TRANSACTION_OBJECT* pobTran);
int inCPACPrintSummaryMiddle(PRINTER_OBJECT* pobPrinter,TRANSACTION_OBJECT* pobTran,int* pinReportTop,int inNumberOfMerchants);

void vdCPACSetSummaryHeaderCondition(int inReportTop,TRANSACTION_OBJECT* pobTran,int inGrandTotals);
void vdCPACSetSummaryMiddleCondition(void);
void vdCPACSetSummaryBottomCondition(TRANSACTION_OBJECT* pobTran,int inFormFeed,CARD_TOTS_REC* srTots);
//void vdSetReceiptFooterConditions (TRANSACTION_OBJECT *pobTran);
//void vdSetPrintReceiptConditions (TRANSACTION_OBJECT *pobTran);
//int inPrintReceiptFooterLines (PRINTER_OBJECT *obPrinter);
//int inCPACPrintDetailGrandTotal(PRINTER_OBJECT *pobPrinter, TRANSACTION_OBJECT *pobTran, int *pinReportTop, int inNumberOfMerchants);

/**** For Status Report Printing ****/
//#ifdef HKGM
extern int inCPACStatReportOperation(TRANSACTION_OBJECT* pobTran);
// #endif /* HKGM */

/**** For Clerk Detail Report Printing ****/
int inCPACClerkDetailReportOperation(TRANSACTION_OBJECT* pobTran);
int inCPACPrintClerkDetailReport(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter);
int inCPACPrintDetailCurrencyReport(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter,int* pinReportTop);
int inCPACPrtClerkDetailMiddle(PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran,DETAIL_TOTALS* psrDetTot);

/**** For Clerk Table Report Printing ****/
int inCPACClerkTableReportOperation(TRANSACTION_OBJECT* pobTran);
int inCPACPrintClerkTableReport(PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran);
/**** For Clerk Total Report Printing ****/
int inCPACClerkTotalsReportOperation(TRANSACTION_OBJECT* pobTran);
int inCPACPrintClerkTotalsReport(TRANSACTION_OBJECT* pobTran,PRINTER_OBJECT* obPrinter);
int inSetCPACMaskTIDMID(TRANSACTION_OBJECT* pobTran, char *tid,char *mid);
/**** Utility Functions for Printing *****/
extern VS_BOOL fGetPrintReceipt(TRANSACTION_OBJECT* pobTran);
#ifdef CITI_PHIL
extern void vdMaskCitiMTID(void);
#endif /* CITI_PHIL */
//Kelvin_F2 --- start: reprint last settlement
extern void vdCPACDisplayNoDataMsg(void);
extern int inCPACRePrintSettlementReport(TRANSACTION_OBJECT* pobTran);
//Kelvin_F2 --- end: reprint last settlement

#ifdef HKGM
extern int inHKGMReprintLastReceiptOperation(TRANSACTION_OBJECT* pobTran);
extern int inHKGMReprintAnyReceiptOperation(TRANSACTION_OBJECT* pobTran);
extern int inHKGMReprintRecpt(long lnInvNum,PRINTER_OBJECT* obPrinter,TRANSACTION_OBJECT* pobTran);
extern int inHKGMGetReceiptCopy(TRANSACTION_OBJECT* pobTran);
#endif /* HKGM */
//Kelvin_f2 --- start: chinese tx code printing & masking PAN
#ifdef HKGM
extern void vdHKGMSetTranCodeCondition(TRANSACTION_OBJECT* pobtran);
#endif /*HKGM*/
//Kelvin_f2 --- end : chinese tx code printing & masking PAN
extern void vdCPACGetMessageFromReceiptFile(long lnMessageIndex,char* szMessageBuffer,TRANSACTION_OBJECT* pobTran);

// #ifdef TLFB (Made this feature as the part of CPAC Base Application)

int inCPACRePrintSettleReport(PRINTER_OBJECT* pobPrinter,TRANSACTION_OBJECT* pobTran);
int inCPACCallReprintSettleReport(TRANSACTION_OBJECT* pobTran);
void vdGetReprintSettleFileName(char* pszFileName,int Choice);

// #endif /* TLFB*/  (Made this feature as the part of CPAC Base Application)
int inCPACReprintAnyReceiptOperation(TRANSACTION_OBJECT* pobTran);
int inPrintFailedSettlementMessage (TRANSACTION_OBJECT *pobTran, PRINTER_OBJECT *obPrinter);

void vdImamReformatDate(char *szDate);

extern int inGetDataLengthFromBatch(TRANSACTION_OBJECT *pobTran, unsigned int uiFieldID);
extern int inGetDataFromBatchToEMVPacket(TRANSACTION_OBJECT *pobTran, unsigned int uiFieldID, int inSize, unsigned char *pbtBuff);
extern int inPrintWatchPacket(unsigned char *pucMessage, int inLen, char*szPrintBuffer);
extern void vdLoadCPACParams(CPAC_REC* psrCPAC);
#endif
